package scream.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import scream.excepcion.DAOExcepcion;
import scream.excepcion.LoginExcepcion;
import scream.negocio.SeguridadNegocioRepresentante;

/**
 * Servlet implementation class RepresentanteServlet
 */
@WebServlet("/RepresentanteServlet")
public class Repre_Insertar_Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public Repre_Insertar_Servlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		String cod_repre = request.getParameter("txt_codRepre");
		String tipo_doc = request.getParameter("cmb_documento");
		String num_doc = request.getParameter("txt_numdoc");
		String ape_pat = request.getParameter("txt_ape_pat");
		String ape_mat = request.getParameter("txt_ape_mat");
		String nombres = request.getParameter("txt_nombre");
		String cargo = request.getParameter("txt_cargo");
		String cod_cli = request.getParameter("txt_cod_cli");
		String cod_gru = request.getParameter("rbg");
		
		

		SeguridadNegocioRepresentante negocio = new SeguridadNegocioRepresentante();

		try {
			negocio.insertarRepresentante(cod_repre, tipo_doc, num_doc,
					ape_pat, ape_mat, nombres, cargo, cod_cli, cod_gru);

			response.sendRedirect(request.getContextPath()
					+ "/Repre_Buscar_Servlet?txt_cod_cli="+cod_cli);

			
		} catch (DAOExcepcion e) {
			System.err.println("Error");
			RequestDispatcher rd = request.getRequestDispatcher("/error_repre.jsp?mierror="+e.getMessage());
			rd.forward(request, response);

		}
	}

}
